<?php


namespace common\command;


use teamones\responseCodeMsg\Generate;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * 生成错误码
 */
class ErrorCodeGenerator extends Command
{
    protected static $defaultName = 'app:generate-errorcode';

    public function __construct(string $name = null)
    {
        parent::__construct($name);
        $this->setAliases(['ger']);
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        // 生成错误码，仅APP_DEBUG模式下生成
        if (empty(C("app_debug"))) {
            return Command::FAILURE;
        }
        $errorCodeConfig = C('error_code');
        $generator = new Generate($errorCodeConfig);
        $generator->run();
        return Command::SUCCESS;
    }
}
